
// roughly equivalent to Python's str.format
String.prototype.format = function(){
    var pattern = /\{\d+\}/g;
    var args = arguments;
    return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
}

// a simple function used by the html rendering of utils.dynforms.ClonerField
function clonerWidget$clone(root_id, counter_id, branch_tag, clone, max_count) {
	var root = document.getElementById(root_id);
	var counter = document.getElementById(counter_id);
	var branch_count = counter.getAttribute("value") * 1;
	if (branch_count < max_count) {
		var branch = document.createElement(branch_tag);
		branch.innerHTML = clone.format(branch_count);
		root.appendChild(branch);
		counter.setAttribute("value", branch_count + 1);
	}
}
